#include "../header/general.h"
#include <algorithm>

const General& General::setName(const std::string& x) {
    name = x;
    return *this;
}

const General& General::setName(std::string&& x) {
    name = std::move(x);
    return *this;
}

const std::string& General::getName() const {
    return name;
}

const General& General::setDesc(const std::string& x) {
    desc = x;
    return *this;
}

const General& General::setDesc(std::string&& x) {
    desc = std::move(x);
    return *this;
}

const std::string& General::getDesc() const {
    return desc;
}

const General& General::setHp(int x) {
    hp = x;
    return *this;
}

int General::getHp() const {
    return hp;
}

const General& General::setCamp(Camp c) {
    camp = c;
    return *this;
}

General::Camp General::getCamp() const {
    return camp;
}

const General& General::setSex(Sex s) {
    sex = s;
    return *this;
}

General::Sex General::getSex() const {
    return sex;
}

const General& General::setSkills(const std::vector<Skill*>& s) {
    skills = s;
    return *this;
}

const General& General::setSkills(std::vector<Skill*>&& s) {
    skills = std::move(s);
    return *this;
}

const std::vector<Skill*>& General::getSkills() const {
    return skills;
}

void General::clear() {
    for(auto & skill : skills) {
        if(skill != nullptr) {
            delete skill;
            skill = nullptr;
        }
    }
}

General::~General() { clear(); }

std::vector<Skill*> General::findByType(Skill::Type type) {
    std::vector<Skill*> res;
    std::copy_if(skills.begin(), skills.end(), std::back_inserter(res), [type](Skill* skill) { return static_cast<short>(skill->getType()) & static_cast<short>(type); });
    return res;
}

std::vector<Skill *> General::findByStage(Skill::Stage stage) {
    std::vector<Skill*> res;
    std::copy_if(skills.begin(), skills.end(), std::back_inserter(res), [stage](Skill* skill) { return static_cast<short>(skill->getStage()) & static_cast<short>(stage); });
    return res;
}

std::vector<Skill *> General::findByCondition(Skill::Condition condition) {
    std::vector<Skill*> res;
    std::copy_if(skills.begin(), skills.end(), std::back_inserter(res), [condition](Skill* skill) { return static_cast<short>(skill->getCondition()) & static_cast<short>(condition); });
    return res;
}
